package usuario;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import persistance.DomainDAO;

public abstract class UsuarioDAO extends DomainDAO{

	@SuppressWarnings("unchecked")
	public static Usuario getByUserName(String username){
		List<Usuario> users = session.createCriteria(Usuario.class).add(Restrictions.eq("nombreUsuario", username)).list();
		if (users == null || users.size() != 1){
			return null;
		}else{
			return users.get(0);
		}
		
		
	}
	
	@SuppressWarnings("unchecked")
	public static Usuario getUserLogin(String username, String pass){
		Criteria criteria = session.createCriteria(Usuario.class).add(Restrictions.eq("nombreUsuario", username));
		criteria.add(Restrictions.eq("contrasena", pass));
		criteria.add(Restrictions.eq("estado", "OP"));
		List<Usuario> users = criteria.list();
		if (users == null || users.size() != 1){
			return null;
		}else{
			return users.get(0);
		}
		
		
	}
}
